<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Product;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;

class ProductController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Product(), function (Grid $grid) {
            $grid->column('id', 'ID')->sortable();
            $grid->column('goods_name_en', '商品名称');
            $grid->column('original_price', '市场价');
            $grid->column('wholesale_price', '批发价');
            $grid->column('colors_en', '颜色');
            $grid->column('sizes', '尺寸');
            $grid->column('created_at', '创建时间');
            $grid->column('updated_at', '更新时间')->sortable();
            //过滤
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });

            //点击当前行任意位置选中
            $grid->rowSelector()->click();
            // 显示编辑按钮
            $grid->showEditButton();
            // 设置分页选择器选项
            $grid->perPages([10, 20, 30, 40, 50]);

            // 默认为每页20条
            $grid->paginate(15);
            // 显示批量删除按钮
            $grid->showBatchDelete();

            // 显示工具栏
            $grid->showToolbar();

            // 显示刷新按钮
            $grid->showRefreshButton();
            // 开启弹窗创建表单
//            $grid->enableDialogCreate();

            // 设置弹窗宽高，默认值为 '700px', '670px'
            $grid->setDialogFormDimensions('60%', '60%');

        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Product(), function (Show $show) {
            $show->field('id', 'ID');
            $show->field('store_goods_url', '商品URL');
            $show->field('store_name', '店铺名称');
            $show->field('store_tel', '店铺联系方式');
            $show->field('store_address', '店铺地址');
            $show->field('goods_name', '商品名称');
            $show->field('goods_name_en', '商品英文名称');
            $show->field('original_price', '市场价格');
            $show->field('wholesale_price', '批发价格');
            $show->field('store_goods_no', '店铺货号');
            $show->field('store_onsale_time', '上市时间');
            $show->field('sizes', '尺寸');
            $show->field('sizes_prices', '尺寸价格');
            $show->field('colors', '颜色');
            $show->field('colors_en', '颜色（英文）');
            $show->field('goods_details', '商品详情');
            $show->field('goods_details_en', '商品详情（英文）');
            $show->field('goods_pics', '商品图片');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Product(), function (Form $form) {
            $sizes = $sizes_prices = $colors = $colors_en = $goods_pics = $store_tels = array();
            $sizes = ['S', 'M', 'L', 'XL'];
            $form->display('id');
            $form->text('store_goods_url', '商品URL');
            $form->text('store_name', '店铺名称');
            $form->multipleSelect('store_tels', '店铺联系方式')->options($store_tels);
            $form->text('store_address', '店铺地址');
            $form->text('goods_name', '商品名称');
            $form->text('goods_name_en', '商品英文名称');
            $form->text('original_price', '市场价格');
            $form->text('wholesale_price', '批发价格');
            $form->text('store_goods_no', '货号');
            $form->text('store_onsale_time', '上市时间');
            $form->multipleSelect('sizes', '尺寸')->options($sizes);
            $form->multipleSelect('sizes_prices', '尺寸价格')->options($sizes_prices);
            $form->multipleSelect('colors', '颜色')->options($colors);
            $form->multipleSelect('colors_en', '颜色（英文）')->options($colors_en);
            $form->textarea('goods_details', '商品详情');
            $form->textarea('goods_details_en', '商品详情（英文）');
            $form->multipleImage('goods_pics', '商品图片')->options($goods_pics);

            //去底部元素
            $form->disableResetButton();
            $form->disableViewCheck();
            $form->disableEditingCheck();
            $form->disableCreatingCheck();
        });
    }

}
